﻿if(!TESTING)
{
    System.Link("StyleSheet", "Themes/Default/Custom.css", "text/css");
}

var Controls = null;
var Window = null, Control = null, RichEditor = null;

function init(completeCallback, errorCallback)
{
    function LoadModulesComplete()
    {
        Controls = System.GetModule("Controls.js");
        CommonDialog = System.GetModule("CommonDialog.js");

        Window = System.GetModule("Window.js").Window;
        Control = System.GetModule("Controls.js").Control;
        
        RichEditor = System.GetModule("RichEditor.js").RichEditor;

        _init(completeCallback, errorCallback);
    }

    System.LoadModules(
        LoadModulesComplete,
        errorCallback,
        ["Window.js", "Controls.js", "RichEditor.js"]
    );
}

function _init(completeCallback, errorCallback)
{
    try
    {
        //初始化代码，初始化完成后必须调用completeCallback;
        completeCallback();
    }
    catch (ex)
    {
        errorCallback(new Exception(ex.mame, ex.message));
    }
}



function dispose(completeCallback, errorCallback)
{
    _dispose(completeCallback, errorCallback);
}

function _dispose(completeCallback, errorCallback)
{
    try
    {
        //卸载代码，卸载完成后必须调用completeCallback;
        completeCallback();
    }
    catch (ex)
    {
        errorCallback(new Exception(ex.mame, ex.message));
    }
}

//共享全局变量和函数，在此定义的变量和函数将由该应用程序的所有实例共享


function Application()
{
    var CurrentApplication = this;
    var m_MainForm = null;
    
    //应用程序全局对象;
        

    this.Start = function(baseUrl)
    {
        //应用程序入口;
        if(TESTING)
        {
            m_MainForm = new Window(
                {
                    Left: 0, Top: 0, Width: 800, Height: 600,
                    Parent: null,
                    Css: "window", BorderWidth: 6,
                    HasMinButton: true, HasMaxButton: true,
                    Title: {
                        InnerHTML: "调试"
                    }
                }
            );
            
            var m_MainWnd = new MainWnd(
                {
                    Left: 0, Top: 0, Width: m_MainForm.GetClientWidth(), Height: m_MainForm.GetClientHeight(),
                    Parent: m_MainForm,
                    AnchorStyle: Controls.AnchorStyle.All,
                    Css: "mainwnd"
                }
            );
            
            m_MainForm.OnClosed.Attach(
                function()
                {
                    CurrentApplication.Dispose();
                }
            );
            
            m_MainForm.MoveEx("center",0,0);
            m_MainForm.Show();
            m_MainForm.Maximun();
        }
        else
        {
            var m_MainWnd = new MainWnd(
                {
                    Left: 0, Top: 0, Width: Desktop.GetClientWidth(), Height: Desktop.GetClientHeight(),
                    Parent: Desktop,
                    AnchorStyle: Controls.AnchorStyle.All,
                    Css: "mainwnd"
                }
            );
        }
        
    }

    this.Terminate = function(completeCallback, errorCallback)
    {
        try
        {
            //应用程序终止，退出系统时用系统调用;
            completeCallback();
        }
        catch (ex)
        {
            errorCallback(new Exception(ex.mame, ex.message));
        }
    }
    

    
    function MainWnd(config)
    {
        var This = this;
        var OwnerForm = this;
        

        
        var width = config.Width, height = config.Height;
        config.Width=517;
        config.Height=414;
    
        Control.call(This, config);
    
        var Base = {
            GetType: This.GetType,
            is: This.is
        };
    
        This.GetType = function() { return "MainWnd"; }
        This.is = function(type) { return type == This.GetType() ? true : Base.is(type); }
        
        var richeditor1 = new RichEditor({"Left":6,"Top":5,"Width":504,"Height":404,"AnchorStyle":Controls.AnchorStyle.Left|Controls.AnchorStyle.Right|Controls.AnchorStyle.Top|Controls.AnchorStyle.Bottom,"Parent":This,"Text":"","Css":"richEditor","BorderWidth":1});
        
        
    
    
        
    
        This.Resize(width,height);
    }

}

